/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAL;
import Entities.TblMarkUpload;
import DatabaseAccess.SQLHelper;
import java.sql.ResultSet;
import java.util.*;
/**
 *
 * @author CuongNV
 */
public class MarkUploadDAL {
     private ResultSet objResult;
    public List<TblMarkUpload> list;

    public MarkUploadDAL() {
    }

    public boolean add(TblMarkUpload markupload) {
        int result = 0;
        String[] params = new String[5];
        params[0] = String.valueOf(markupload.getExamId());
        params[1] = String.valueOf(markupload.getClassId());
        params[2] = String.valueOf(markupload.getStaffuploadId());
        params[3] = String.valueOf(markupload.getTeachergradingId());
        params[4] = String.valueOf(markupload.getStatus());
        try {
            result = SQLHelper.executeUpdate("ProcInsertMarkUpload", params);
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
        }

        return result == 1 ? true : false;
    }

    public boolean update(TblMarkUpload markupload) {
        int result = 0;
        String[] params = new String[3];
        params[0] = String.valueOf(markupload.getExamId());
        params[1] = String.valueOf(markupload.getClassId());
        params[2] = String.valueOf(markupload.getStatus());

        try {
            result = SQLHelper.executeUpdate("procUpdateMarkUpload", params);
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
        }

        return result == 1 ? true : false;
    }
    
    public List<TblMarkUpload> getExamEndClassByFacultyId(int facultyId) {
        list = new ArrayList<TblMarkUpload>();
        String[] params = new String[1];
        params[0] = String.valueOf(facultyId);
        try {
            objResult = SQLHelper.executeQuery("procGetExaminationByFacultyId", params);
            while (objResult.next()) {
                TblMarkUpload markupload = new TblMarkUpload();
                markupload.setExamId(objResult.getInt("ExamId"));
                markupload.setClassId(objResult.getInt("ClassId"));
                markupload.setStaffuploadId(objResult.getInt("StaffUploadId"));
                markupload.setTeachergradingId(objResult.getInt("TeacherGradingId"));
                markupload.setStatus(objResult.getInt("Status"));

                list.add(markupload);
            }

            return list;
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
            return null;
        }
    }
}
